package main

import (
	"chat-room/client/action"
	"chat-room/client/global"
	"fmt"
	"gopkg.in/yaml.v2"
	"io/ioutil"
	"net"
)

//初始化配置
func init() {
	data, err := ioutil.ReadFile("../config/config.yaml")
	if err != nil {
		fmt.Printf("读取配置文件错误：%v",err)
		return
	}
	err = yaml.Unmarshal(data, &global.YamlConfig)
	if err != nil {
		fmt.Printf("解析配置文件错误：%v",err)
		return
	}
}
func main() {
	var err error
	global.Conn, err = net.Dial(
		global.YamlConfig.Tcp.Network,
		global.YamlConfig.Tcp.Address + ":" + global.YamlConfig.Tcp.Port,
	)
	if err != nil {
		errStr := fmt.Sprintf("连接服务器失败：%v",err)
		fmt.Println(errStr)
		return
	}
	//延时关闭连接
	defer func() {
		_ = global.Conn.Close()
	}()

	//显示菜单
	viewEx := &action.View{}
	viewEx.ShowHomeMenu()
}
